﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command;
using B.S.DataBase.MyRead.API.DTOs;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler
{
    public class GetChildMenusCommendHandlers : IRequestHandler<GetChildMenusCommends, APIResult<object>>
    {
        private readonly IBaseRepository<Menu> menuRepository;
        private readonly IMapper mapper;

        public GetChildMenusCommendHandlers(IBaseRepository<Menu> menuRepository, IMapper mapper)
        {
            this.menuRepository = menuRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 查询子菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<object>> Handle(GetChildMenusCommends request, CancellationToken cancellationToken)
        {
            APIResult<object> result=new APIResult<object>();
     
            var menus=menuRepository.GetAll().Where(m => m.ParentMenuId == request.MenuID&&m.IsDel==false).Count();
            if (menus == 1)
            {
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = menus;
            }
            else
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
                result.data = menus;
            }


            return Task.FromResult(result);
        }

       

    }
}
